<?php

/*
=====================================================
 FluxBB - Delux Board Converstations (DBC)
-----------------------------------------------------
 http://dbc-forum.com/
 http://fluxbb.org/
-----------------------------------------------------
 Copyright (c) 2010,2011 FluxBB - Delux Board Conversations (DBC)
-----------------------------------------------------
 Предсловие: Данный скрипт (DBC) не является работой с нуля, то 
 есть ядром скрипта всё также остаётся FuxBB,но теперь в оболочке
 DBC.
=====================================================
*/

if (!defined('DBC') || !defined('DBC_PMS_NEW'))
	exit;

define('DBC_PMS_LOADED', 1);

$tid = isset($_GET['tid']) ? intval($_GET['tid']) : 0;

if ($tid < 1)
	message($lang_common['Bad request']);

if (!in_array($tid, $pmsn_arr_save))
	message($lang_common['Bad request']);

$result = $db->query('SELECT * FROM '.$db->prefix.'pms_new_topics WHERE id='.$tid) or error('Unable to fetch pms_new_topics info', __FILE__, __LINE__, $db->error());

if (!$db->num_rows($result))
	message($lang_common['Bad request']);

$cur_topic = $db->fetch_assoc($result);

if ($DBC_user['id'] != $cur_topic['starter_id'] || $cur_topic['see_to'] != 0)
	message($lang_common['Bad request']);

if ($DBC_user['g_pm_limit'] != 0 && $pmsn_kol_list >= $DBC_user['g_pm_limit'])
	message($lang_pmsn['More maximum list']);

$result = $db->query('SELECT u.*, g.* FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id WHERE id='.$cur_topic['to_id']) or error('Unable to fetch user information', __FILE__, __LINE__, $db->error());
$cur_user = $db->fetch_assoc($result);

if (!isset($cur_user['id']))
	message($lang_pmsn['No addressee']);
else if ($cur_user['id'] == $DBC_user['id'])
	message($lang_pmsn['No for itself']);
if ($DBC_user['g_id'] != DBC_ADMIN)
{
	if ($cur_user['messages_enable'] == 0 || $cur_user['g_pm'] == 0)
		message($lang_pmsn['Off messages']);
	else if ($cur_user['messages_all'] >= $cur_user['g_pm_limit'] && $cur_user['g_pm_limit'] != 0)
		message($lang_pmsn['More maximum']);
}

if (isset($_POST['action2']))
{
	if (!defined('DBC_PMS_NEW_CONFIRM'))
		message($lang_common['Bad referrer']);

	$db->query('UPDATE '.$db->prefix.'pms_new_topics SET topic_st=0, topic_to=1 WHERE id='.$tid) or error('Unable to update pms_new_topics', __FILE__, __LINE__, $db->error());
	
  pmsn_user_update($cur_user['id'], true);
  pmsn_user_update($DBC_user['id']);

	if ($cur_user['messages_email'] == 1)
	{
		$mail_tpl = trim(file_get_contents(DBC_ROOT.'language/'.$cur_user['language'].'/mail_templates/form_pmsn.tpl'));

		$first_crlf = strpos($mail_tpl, "\n");
		$mail_subject = DBC_trim(substr($mail_tpl, 8, $first_crlf-8));
		$mail_message = DBC_trim(substr($mail_tpl, $first_crlf));

		$mail_subject = str_replace('<mail_subject>', $cur_topic['topic'], $mail_subject);
		$mail_message = str_replace('<sender>', $DBC_user['username'], $mail_message);
		$mail_message = str_replace('<user>', $cur_user['username'], $mail_message);
		$mail_message = str_replace('<board_title>', $DBC_config['o_board_title'], $mail_message);
		$mail_message = str_replace('<board_mailer>', $DBC_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message);
		$mail_message = str_replace('<message_url>', $DBC_config['o_base_url'].'/pmsnew.php?mdl=topic&tid='.$tid, $mail_message);

		require_once DBC_ROOT.'engine/email.php';

		DBC_mail($cur_user['email'], $mail_subject, $mail_message, $DBC_user['email'], $DBC_user['username']);
	}

	redirect('pmsnew.php?mdl=list'.$sidamp, $lang_pmsn['List redirect']);
}

define('DBC_ACTIVE_PAGE', 'pms_new');
require DBC_ROOT.'engine/engine.php';
?>

<?php

generate_pmsn_menu($pmsn_modul);

?>
	<div class="blockform">


		<div class="pagepost_pm">
			<span class="contacts"><a href="index.php"><?php echo $lang_common['Index'] ?></a>
			<span>»&#160;</span><a href="pmsnew.php"><?php echo $lang_pmsn['PM'] ?></a>
			<span>»&#160;</span><?php echo $lang_pmsn[$pmsn_modul].($sid ? $lang_pmsn['With'].$siduser : '') ?>
		</div>
		<div class="clearer"></div>





	<table width="100%" height="38" border="0" cellpadding="0" cellspacing="0"><thead><tr>
	<td align="left" width="28" class="bg_forum_title_left"><img src="engine/skins/images/spacer.gif" border="0"></td>
	<td align="left" class="bg_forum_title_center"><span class="cat_title"><?php echo sprintf($lang_pmsn['InfoSend'], DBC_htmlspecialchars($cur_topic['topic'])) ?></span></td>
	<td align="center" width="28" class="bg_forum_title_right"><img src="engine/skins/images/spacer.gif" border="0"></td>
	</tr></table>
	
	<table class="forum_adv_table"  width="100%" border="0" cellpadding="0" cellspacing="0"><thead><tr>
	<td align="left" class="forum_adv_tleft" width="2"><img src="engine/skins/images/spacer.gif" border="0"></td>
	<td align="left" width="100%"><div class="forum_adv2">


			<form method="post" action="pmsnew.php?mdl=send&amp;tid=<?php echo $tid.$sidamp ?>">
				<div class="inform">
					<input type="hidden" name="csrf_hash" value="<?php echo $pmsn_csrf_hash ?>" />
					<fieldset>
						<legend><?php echo $lang_pmsn['Attention'] ?></legend>
						<div class="infldset">
							<p><?php echo sprintf($lang_pmsn['InfoSendQ'], DBC_htmlspecialchars($cur_user['username'])) ?></p>
						</div>
					</fieldset>
					<p class="buttons"><input type="submit" class="fbutton" name="action2" value="<?php echo $lang_common['Submit'] ?>" /></p>
				</div>
			</form>



<br/>
</div></td>
<td align="left" class="forum_adv_tright" width="2"><img src="engine/skins/images/spacer.gif" border="0"></td>
</td></tr></table>
<table width="100%" height="23" border="0" cellpadding="0" cellspacing="0"><thead><tr>
<td align="left" width="30" class="bg_forum_bott_left"><img src="engine/skins/images/spacer.gif" border="0"></td>
<td align="left" class="bg_forum_bott_center"><img src="engine/skins/images/spacer.gif" border="0"></td>
<td align="center" width="30" class="bg_forum_bott_right"><img src="engine/skins/images/spacer.gif" border="0"></td>
</tr></thead></table>





	</div>







<?php

